home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / satellit / im2gif / inter.c < prev    next >
Text File  |  1991-11-24  |  4KB  |  170 lines

  1. /* interlace fields from uosat pics and make even number of pixels per line.
  2.  
  3. 24NOV91 NK6K
  4.  
  5. Add header offset to release version.  Current header size is 256 bytes.
  6.  
  7. 21JUL91 NK6K
  8.  
  9. This program takes a UoSAT-5 CCD 2-field image and interlaces them into
  10. one flat raster file.  It also adds a 0 pixel to the end of each line,
  11. the rg8 program used to convert the raster file to .GIF doesn't like
  12. odd line lengths when using the /2 option.
  13.  
  14. Suggested usage:
  15.  
  16. inter ccdn ccdni
  17. rg8 ccdni. /c612 /r578
  18.  
  19. Harold
  20.  
  21. Added 7/28/91
  22. Remove first four bytes from file, this avoids the wrap-around effect.
  23.  
  24.  
  25. Note:  Some early image files on UO-22 had missing or duplicate blocks,
  26. this will cause this program to emit an incorrect raster file.
  27.  
  28. From UoSAT:
  29.  
  30. The  data  format  that  will be used to  transfer  image  data  from  the 
  31. transputer to the OBC is described as follows.
  32.  
  33. The image frame is composed of two interleaved fields of 288 lines by  611 
  34. pixels  each,  combined to give a total image of 576 by  611.   The  total 
  35. length  of an image file is 352048 bytes, with the extra bytes due to  the 
  36. positional offset between the two fields.
  37.  
  38. When reading the file, the first byte corresponds to the grey level of the 
  39. top  leftmost pixel.  The follow bytes define the pixels to the  right  of 
  40. the  first  one until the end of the first line  is  reached.   Subsequent 
  41. lines  are  aligned below this one for the rest of the first  field  (i.e. 
  42. line 288).  
  43.  
  44. Line  289 is the first line in the second field.  At this point 355  bytes 
  45. (i.e.  half  a  line) must be read and discarded to ensure  that  the  two 
  46. fields align properly.
  47.  
  48. Because the two fields are interlaced, the lines in the second field  must 
  49. be  placed in between the lines of the first field as shown  below.   This 
  50. implies that when the first field is displayed, adequate room must be left 
  51. for the insertion of the second field.
  52.  
  53. When a full frame is displayed the arrangement of the lines should be:
  54.  
  55.      Line 1
  56.      Line 289
  57.      Line 2
  58.      Line 290
  59.      Line 3
  60.      ....
  61.      ....
  62.      Line 574
  63.      Line 287
  64.      Line 575
  65.      Line 288
  66.      Line 576.
  67.  
  68. */
  69. #include <stdio.h>
  70. #include <dos.h>
  71. #include <fcntl.h>
  72. #include <sys\types.h>
  73. #include <sys\stat.h>
  74.  
  75. #define LINE_SIZE 611
  76. #define NUM_LINE_FIELD 288
  77. #define HEADER_OFFSET 256l
  78.  
  79. long start_field_2;
  80. int lines=0;
  81. int skip_lines=0;
  82.  
  83. char buff[LINE_SIZE+1];
  84. int fillval=0;
  85.  
  86. main(argc,argv)
  87. int argc;
  88. char *argv[];
  89. {
  90.  
  91.     int fi1,fi2,fo;
  92.     int i;
  93.  
  94.     start_field_2 = ((long)LINE_SIZE*(long)NUM_LINE_FIELD)+355l;
  95.  
  96.  
  97.     if (argc<2) {
  98.         printf ("usage: inter input output [skip_lines]\n");
  99.         printf ("skip - number of lines from start of image to not\n");
  100.         printf ("include in the output file");
  101.         exit(1);
  102.     }
  103.  
  104.     if (argc>3) skip_lines = atoi(argv[3]);
  105.  
  106.     if ((fi1= open(argv[1], O_BINARY)) == -1){
  107.         printf("cannot open: %s\n",argv[1]);
  108.         perror("On input file");
  109.         exit(1);
  110.     }
  111.  
  112.     if ((fi2= open(argv[1], O_BINARY)) == -1){
  113.         printf("cannot open: %s\n",argv[1]);
  114.         perror("On input file");
  115.         exit(1);
  116.     }
  117.  
  118.     lseek(fi2,start_field_2+4l+HEADER_OFFSET,SEEK_SET);
  119.     lseek(fi1,4l+HEADER_OFFSET,SEEK_SET);
  120.  
  121.  
  122.     if ((fo = open(argv[2], 0)) != -1){
  123.         printf("output file exists.  Aborted\n");
  124.         exit(1);
  125.     }
  126.  
  127.     if ((fo = open(argv[2],O_CREAT | O_TRUNC | O_BINARY | O_RDWR, S_IREAD | S_IWRITE)) == -1) {
  128.         printf("cannot open: %s\n",argv[2]);
  129.         perror("On output file");
  130.         exit(1);
  131.     }
  132.  
  133.     
  134.     buff[LINE_SIZE+1]=0;
  135.     for (i=0;i<NUM_LINE_FIELD;i++) {
  136.  
  137.             /* If file is short, fill with zeroes */
  138.         memset(buff,0,LINE_SIZE+1);
  139.         if (read(fi1, buff, LINE_SIZE)==-1) {
  140.             perror("On input file 1st field\n");
  141.             exit(1);
  142.         }
  143.         if (lines >= skip_lines) {
  144.          if (write(fo,buff,LINE_SIZE+1)==-1) {
  145.             perror("On output file 1st field\n");
  146.             exit(1);
  147.          }
  148.         }
  149.  
  150.         memset(buff,0,LINE_SIZE+1);
  151.         if (read(fi2, buff, LINE_SIZE)==-1) {
  152.             perror("On input file 2nd field\n");
  153.             exit(1);
  154.         }
  155.  
  156.         if (lines >= skip_lines) {
  157.          if (write(fo,buff,LINE_SIZE+1)==-1) {
  158.             perror("On output file 2nd field\n");
  159.             exit(1);
  160.          }
  161.         }
  162.         lines++;
  163.     }
  164.     close (fo);
  165.     close (fi1);
  166.     close (fi2);
  167.  
  168. }
  169.  
  170.